package com.xiaotu.core.asyncs;

import com.xiaotu.zhouyi.pojo.entity.TGuaSixtyfour;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * @Author xiaotu
 * @Description //TODO
 * @Date 2022/1/19 15:50
 * @ClassName AsyncsXiaotu
 * @Version 1.0
 **/
@Component
public class AsyncsXiaotu {
    @Autowired
    private  RedisTemplate redisTemplate;
    @Async
    public void redisMethod(Object list, String key,Long times){
        try {
            //开启异步使用Redis
            redisTemplate.opsForValue().set(key,list);
            //设置60s缓存过期时间
            redisTemplate.expire(key, times, TimeUnit.SECONDS);
            //Thread.sleep(5000);
            System.out.println("=========>异步使用Redis缓存");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
